﻿using System;
using System.Runtime.Serialization;

namespace SBPweb.Services.Base
{

    public class ServiceMethodResult<TCode, TValue>
    {

        #region Private fields

        private TCode resultCode;
        private TValue resultValue;

        #endregion

        #region Constructor logic
        
        public ServiceMethodResult()
        {
        }

        public ServiceMethodResult(TCode code, TValue value)
        {
            resultCode = code;
            resultValue = value;
        }

        #endregion

        #region Property accessors

        public TCode Code
        {
            get
            {
                return resultCode;
            }
            set
            {
                resultCode = value;
            }
        }

        public TValue Value
        {
            get
            {
                return resultValue;
            }
            set
            {
                resultValue = value;
            }
        }

        #endregion

    }

    public class ServiceResultCode
    {

        #region Constants

        public const int Unknown = -1;
        public const int Ok = 0;
        public const int Error = 1;

        #endregion

        #region Constructor logic

        internal ServiceResultCode(int value)
        {
            Value = value;
        }

        public static ServiceResultCode CreateByCode(int value)
        {
            return new ServiceResultCode(value);
        }

        #endregion

        #region Property accessors

        public int Value;

        #endregion

        #region Methods

        public override bool Equals(object obj)
        {
            return Value.Equals(obj);
        }

        public override string ToString()
        {
            return Value.ToString();
        }

        #endregion

    }

    public class ServiceMethodResult : ServiceMethodResult<ServiceResultCode, ISerializable>
    {
        
        #region Constructor logic
        
        public ServiceMethodResult()
            : base()
        {
        }

        public ServiceMethodResult(ServiceResultCode code, ISerializable value)
            : base(code, value)
        {
        }

        #endregion

    }

}